#include "Vector2.h"
#include <math.h>

Vector2::~Vector2(void)
{
}

double Vector2::magnitude() const {
	return sqrt(pow(x, 2) + pow(y, 2));
}

double Vector2::angle() const {
	return atan2(y, x);
}

Vector2 Vector2::normalize() const {
	double mag = magnitude();
	return Vector2(x / mag, y / mag);
}

Vector2 Vector2::operator*(double scale) {
	return Vector2(this->x * scale, this->y * scale);
}

Vector2 Vector2::operator/(double scale) {
	return Vector2(this->x / scale, this->y / scale);
}

Vector2 Vector2::operator+(const Vector2 & rhs) {
	return Vector2(this->x + rhs.x, this->y + rhs.y);
}

Vector2 Vector2::operator-(const Vector2 & rhs) {
	return Vector2(this->x - rhs.x, this->y - rhs.y);
}

void Vector2::operator=(const Vector2 & rhs) {
	this->x = rhs.x;
	this->y = rhs.y;
}

void Vector2::operator+=(const Vector2 & rhs) {
	this->x += rhs.x;
	this->y += rhs.y;
}

void Vector2::operator-=(const Vector2 & rhs) {
	this->x -= rhs.x;
	this->y -= rhs.y;
}

void Vector2::operator*=(double scale) {
	this->x *= scale;
	this->y *= scale;
}

void Vector2::operator/=(double scale) {
	this->x /= scale;
	this->y /= scale;
}

double Vector2::dot(const Vector2 & v1, const Vector2 & v2) {
	Vector2 v1n = v1.normalize();
	Vector2 v2n = v2.normalize();

	return v1n.x * v2n.x + v1n.y * v2n.y;
}